﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PMPUtils.Form;
using PMPUtils.Goals;

namespace PMP.Goals
{
    public partial class GoalDetailManagement : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FormUtil.Authenticate(Session, Response);

            if (!IsPostBack)
            {
                txtGoalDetail.Text = Request.Params["GOALDETAIL"];
                txtTaskID.Text = Request.Params["TASK"];
            }
        }

        protected void btnUpdateOwner_Click(object sender, EventArgs e)
        {
            PopupForm ViewGoalDetails = new PopupForm(Response, "GoalDetailManagement_SwitchOwner.aspx?GOALDETAIL=" + txtGoalDetail.Text.Trim(), "GoalDetailManagement_SwitchOwner", "350", "150", "400", "200");
            ViewGoalDetails.Popup();

            Close();
        }

        protected void btnUpdateStatus_Click(object sender, EventArgs e)
        {
            PopupForm ViewGoalDetails = new PopupForm(Response, "GoalDetailManagement_ChangeStatus.aspx?GOALDETAIL=" + txtGoalDetail.Text.Trim(), "GoalDetailManagement_ChangeStatus", "350", "150", "400", "200");
            ViewGoalDetails.Popup();

            Close();
        }

        protected void btnUpdateDueDate_Click(object sender, EventArgs e)
        {
            PopupForm updateDueDate = new PopupForm(Response, "GoalDetailManagement_ChangeDueDate.aspx?GOALDETAIL=" + txtGoalDetail.Text.Trim(), "GoalDetailManagement_ChangeDueDate", "350", "300", "400", "200");
            updateDueDate.Popup();

            Close();
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            String goalDetailID = txtGoalDetail.Text.Trim();

            try
            {
                GoalDetailsOperator.RemoveGoalDetail(goalDetailID);
            }
            catch (Exception ex)
            {
                Messenger.Show(Response, "Error: " + ex.Message);
                return;
            }

            Messenger.Show(Response, "Delete Successfully.");

            Close();
        }

        protected void btnUpdateExpectedDueDate_Click(object sender, EventArgs e)
        {
            PopupForm updateExpDueDate = new PopupForm(Response, "GoalDetailManagement_ChangeExpectedDueDate.aspx?GOALDETAIL=" + txtGoalDetail.Text.Trim(), "GoalDetailManagement_ChangeExpectedDueDate", "350", "300", "400", "200");
            updateExpDueDate.Popup();

            Close();
        }

        private void Close()
        {
            PopupForm thisForm = new PopupForm(Response);
            thisForm.Close();
        }

        protected void btnCheckList_Click(object sender, EventArgs e)
        {
            PopupForm checklist = new PopupForm(Response, "../Checklist/Dashboard.aspx?TASKID=" + txtTaskID.Text.Trim(), "ChecklistDashboard", "1000", "600", "50", "100");
            checklist.Popup();

            Close();
        }
    }
}
